import 'package:flutter/material.dart';// 默认主题
import 'package:flutter/cupertino.dart'; // 苹果主题
import 'package:flutter/foundation.dart';// defaultTargetPlatform判断操作系统
import 'package:flutter_demo/views/demo.dart';
import 'package:flutter_demo/views/demo/demo1.dart';
import 'package:flutter_demo/views/demo/demo10.dart';
import 'package:flutter_demo/views/demo/demo2.dart';
import 'package:flutter_demo/views/demo/demo3.dart';
import 'package:flutter_demo/views/demo/demo4.dart';
import 'package:flutter_demo/views/demo/demo5.dart';
import 'package:flutter_demo/views/demo/demo6.dart';
import 'package:flutter_demo/views/demo/demo7.dart';
import 'package:flutter_demo/views/demo/demo8.dart';
import 'package:flutter_demo/views/demo/demo9.dart';
import 'package:flutter_demo/views/home.dart';
import 'package:flutter_demo/views/mine.dart';
import 'package:flutter_demo/views/other.dart';
import 'package:flutter_demo/views/test.dart';

final ThemeData kIOSTheme = new ThemeData(    //Cupertino主题风格
  primarySwatch: Colors.orange,
  primaryColor: Colors.grey[100],
  primaryColorBrightness: Brightness.light,
);

final ThemeData kDefaultTheme = new ThemeData(    //默认的Material主题风格
  primaryColor: Colors.blue,
  primarySwatch: Colors.blue,
  accentColor: Colors.blue,
);
void main(){
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Welcome to Flutter',
      home: new MainWidget(),
      routes: {
        "other" : (context) => new Other(),
        "demo1" : (context) => new Demo1(),
        "demo2" : (context) => new Demo2(),
        "demo3" : (context) => new Demo3(),
        "demo4" : (context) => new Demo4(),
        "demo5" : (context) => new Demo5(),
        "demo6" : (context) => new Demo6(),
        "demo7" : (context) => new Demo7(),
        "demo8" : (context) => new Demo8(),
        "demo9" : (context) => new Demo9(),
        // "demo10" : (context) => new Demo10(),
      },
      onGenerateRoute: (settings) {// routes中没有匹配到的路由则交由onGenerateRoute处理
        switch (settings.name) {
          case 'demo10':
            return CupertinoPageRoute(builder: (ctx) {
              return new Demo10();
            });
            break;
          default:
            return null;
        }
      },
      theme: defaultTargetPlatform == TargetPlatform.iOS         //defaultTargetPlatform用于识别操作系统，不过其实Theme.of(context).platform也同样可以获得操作系统标识
        ? kIOSTheme                                              
        : kDefaultTheme,
    );
  }
}

class MainWidget extends StatefulWidget {
  @override
  createState() => new MainState();
}

class MainState extends State<MainWidget> {
  int _tabIndex = 0;
  List<Widget> pages = [
    new Home(),
    new Mine(),
    new Test(data: 'wqeqeqewq'),
    new Demo()
  ];
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: pages[_tabIndex],
      bottomNavigationBar: new BottomNavigationBar(
        type: BottomNavigationBarType.fixed,// 加上fixed属性，解决item超过3个时BottomNavigationBar不显示的问题
        items: <BottomNavigationBarItem>[
          // new BottomNavigationBarItem(
          //     icon: Image.asset('images/read.png', width: 24.0, height: 24.0), title: new Text('列表')),
          // new BottomNavigationBarItem(
          //     icon: Image.asset('images/user.png', width: 24.0, height: 24.0), title: new Text('我的')),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.list), title: new Text('首页')),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.account_box), title: new Text('我的')),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.account_box), title: new Text('测试')),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.account_box), title: new Text('demo')),
        ],
        currentIndex: _tabIndex,
        iconSize: 24.0,
        onTap: (index) {
          setState(() {
            _tabIndex = index;
          });
        },
      ),
    );
  }
}